package qianfeng.com.fan_shu_xiao_bao.view;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import butterknife.ButterKnife;
import butterknife.InjectView;
import qianfeng.com.fan_shu_xiao_bao.R;
import qianfeng.com.fan_shu_xiao_bao.view.Information.InformationFragment;
import qianfeng.com.fan_shu_xiao_bao.view.base.BaseActivity;
import qianfeng.com.fan_shu_xiao_bao.view.base.BaseFragment;
import qianfeng.com.fan_shu_xiao_bao.view.find.FindFragment;
import qianfeng.com.fan_shu_xiao_bao.view.my.MyFragment;
import qianfeng.com.fan_shu_xiao_bao.view.school.SchoolFragment;
import qianfeng.com.fan_shu_xiao_bao.view.video.VideoFragment;

/**
 * 最外层主界面
 */
/*
大多列表页面都有功能:第一层是以前浏览到的位置,下面才是新的数据，中间会用提示分开(上次看到了这里哦,点击推荐更多^ ^)

学院一级页面不会在断网时失去数据

咨询的GIF图若播放过,可以在断网时播放
咨询与页面所有列表数据若有加载过,在断网时也会有数据

外层效果:不可以滑动切换页面，却在点击切换的时候有滑动效果


id命名规范 : 所在容器_所在类_(此控件标志 可无)_此控件类型  例如:  fragment_information_TabLayout

类名命名规范 : 如果是继承了特殊的类(例如fragment,activity,adapter)类名的最后必须有相应的关键字
    类名要大体能看出该类是什么作用


 */
public class MainActivity extends BaseActivity {

    @InjectView(R.id.main_viewPager)
    ViewPager viewPager;
    @InjectView(R.id.main_radioGroup)
    RadioGroup radioGroup;

    private BaseFragment fragments[];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);

        initFragments();
        initView();


    }

    private void initFragments() {
        fragments = new BaseFragment[5];
        fragments[0] = new InformationFragment();
        fragments[1] = new VideoFragment();
        fragments[2] = new SchoolFragment();
        fragments[3] = new FindFragment();
        fragments[4] = new MyFragment();
    }

    private void initView() {
        viewPager.setAdapter(new Main_ViewPager_Adapter(getSupportFragmentManager(), fragments));

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                for (int i = 0; i < fragments.length; i++) {
                    boolean checked = ((RadioButton) group.getChildAt(i)).isChecked();
                    if (checked == true) {
                        viewPager.setCurrentItem(i);
                    }
                }
            }
        });
        ((RadioButton) radioGroup.getChildAt(0)).setChecked(true);
    }
}
